<template>
  <a-drawer
    :title="title"
    :width="width"
    placement="right"
    :closable="false"
    @close="close"
    :visible="visible">
  
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item label="生产订单编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'ipoNo', validatorRules.ipoNo]" placeholder="请输入生产订单编号"></a-input>
        </a-form-item>
        <a-form-item label="采购方总部编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'puchaserHqCode', validatorRules.puchaserHqCode]" placeholder="请输入采购方总部编码"></a-input>
        </a-form-item>
        <a-form-item label="供应商编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'supplierCode', validatorRules.supplierCode]" placeholder="请输入供应商编号"></a-input>
        </a-form-item>
        <a-form-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'remark', validatorRules.remark]" placeholder="请输入备注"></a-input>
        </a-form-item>
        <a-form-item label="逻辑删除" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'isDeleted', validatorRules.isDeleted]" placeholder="请输入逻辑删除"></a-input>
        </a-form-item>
        <a-form-item label="产品" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'insideNo', validatorRules.insideNo]" placeholder="请输入产品"></a-input>
        </a-form-item>
        <a-form-item label="设备编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'deviceNo', validatorRules.deviceNo]" placeholder="请输入设备编号"></a-input>
        </a-form-item>
        <a-form-item label="生产批次号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'productBatchNo', validatorRules.productBatchNo]" placeholder="请输入生产批次号"></a-input>
        </a-form-item>
        <a-form-item label="工序数据" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'processName', validatorRules.processName]" placeholder="请输入工序数据"></a-input>
        </a-form-item>
        <a-form-item label="订单状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'orderStatus', validatorRules.orderStatus]" placeholder="请输入订单状态"></a-input>
        </a-form-item>
        <a-form-item label="客户所属省份" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'buyerProvince', validatorRules.buyerProvince]" placeholder="请输入客户所属省份"></a-input>
        </a-form-item>
        <a-form-item label="数据拥有方" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'ownerId', validatorRules.ownerId]" placeholder="请输入数据拥有方"></a-input>
        </a-form-item>
        <a-form-item label="品类" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'categoryCode', validatorRules.categoryCode]" placeholder="请输入品类"></a-input>
        </a-form-item>
        <a-form-item label="subclassCode" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'subclassCode', validatorRules.subclassCode]" placeholder="请输入subclassCode"></a-input>
        </a-form-item>
        <a-form-item label="计划开始时间,格式：YYYY-MM-DD hh:mm:ss" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'planStartTime', validatorRules.planStartTime]" placeholder="请输入计划开始时间,格式：YYYY-MM-DD hh:mm:ss"></a-input>
        </a-form-item>
        <a-form-item label="计划结束时间,格式：YYYY-MM-DD hh:mm:ss" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'planEndTime', validatorRules.planEndTime]" placeholder="请输入计划结束时间,格式：YYYY-MM-DD hh:mm:ss"></a-input>
        </a-form-item>
        <a-form-item label="开始时间,格式：YYYY-MM-DD hh:mm:ss" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'actualStartTime', validatorRules.actualStartTime]" placeholder="请输入开始时间,格式：YYYY-MM-DD hh:mm:ss"></a-input>
        </a-form-item>
        <a-form-item label="结束时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'actualEndTime', validatorRules.actualEndTime]" placeholder="请输入结束时间"></a-input>
        </a-form-item>
        <a-form-item label="数据可见方" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'openId', validatorRules.openId]" placeholder="请输入数据可见方"></a-input>
        </a-form-item>
        <a-form-item label="主键ID值" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'workId', validatorRules.workId]" placeholder="请输入主键ID值" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="全局交易流水号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'transno', validatorRules.transno]" placeholder="请输入全局交易流水号"></a-input>
        </a-form-item>
        <a-form-item label="1：未读（默认状态）
0：成功；" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'ioflag', validatorRules.ioflag]" placeholder="请输入1：未读（默认状态）
0：成功；"></a-input>
        </a-form-item>
        <a-form-item label="错误信息，接口同步返回消息" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'message', validatorRules.message]" placeholder="请输入错误信息，接口同步返回消息"></a-input>
        </a-form-item>
        <a-form-item label="本条数据值新增/更新，0：新增，1：更新" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'status', validatorRules.status]" placeholder="请输入本条数据值新增/更新，0：新增，1：更新"></a-input>
        </a-form-item>
        <a-form-item label="工序编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'processCode', validatorRules.processCode]" placeholder="请输入工序编码"></a-input>
        </a-form-item>
        <a-form-item label="生产工艺路线编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'processNo', validatorRules.processNo]" placeholder="请输入生产工艺路线编码"></a-input>
        </a-form-item>
        <a-form-item label="生产车间id" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'workshopId', validatorRules.workshopId]" placeholder="请输入生产车间id"></a-input>
        </a-form-item>
        <a-form-item label="生产车间编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'workshopCode', validatorRules.workshopCode]" placeholder="请输入生产车间编码"></a-input>
        </a-form-item>
        <a-form-item label="生产车间名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'workshopName', validatorRules.workshopName]" placeholder="请输入生产车间名称"></a-input>
        </a-form-item>
        <a-form-item label="生产工单编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'woNo', validatorRules.woNo]" placeholder="请输入生产工单编号"></a-input>
        </a-form-item>
        <a-form-item label="实物id，如国网实物id" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'productId', validatorRules.productId]" placeholder="请输入实物id，如国网实物id"></a-input>
        </a-form-item>
        <a-form-item label="数据来源" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'dataSource', validatorRules.dataSource]" placeholder="请输入数据来源"></a-input>
        </a-form-item>
        <a-form-item label="来源数据创建时间 yyyy-MM-dd HH:mm:ss" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'dataSourceCreateTime', validatorRules.dataSourceCreateTime]" placeholder="请输入来源数据创建时间 yyyy-MM-dd HH:mm:ss"></a-input>
        </a-form-item>
        <a-form-item label="推送时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择推送时间" v-decorator="[ 'pushTime', validatorRules.pushTime]" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        
      </a-form>
    </a-spin>
    <a-button type="primary" @click="handleOk">确定</a-button>
    <a-button type="primary" @click="handleCancel">取消</a-button>
  </a-drawer>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import JDate from '@/components/jeecg/JDate'  
  
  export default {
    name: "ZxjEipBgModal",
    components: { 
      JDate,
    },
    data () {
      return {
        title:"操作",
        width:800,
        visible: false,
        model: {},
        url: {
        }
     
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'ipoNo','puchaserHqCode','supplierCode','remark','isDeleted','insideNo','deviceNo','productBatchNo','processName','orderStatus','buyerProvince','ownerId','categoryCode','subclassCode','planStartTime','planEndTime','actualStartTime','actualEndTime','openId','workId','transno','ioflag','message','status','processCode','processNo','workshopId','workshopCode','workshopName','woNo','productId','dataSource','dataSourceCreateTime','pushTime'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'ipoNo','puchaserHqCode','supplierCode','remark','isDeleted','insideNo','deviceNo','productBatchNo','processName','orderStatus','buyerProvince','ownerId','categoryCode','subclassCode','planStartTime','planEndTime','actualStartTime','actualEndTime','openId','workId','transno','ioflag','message','status','processCode','processNo','workshopId','workshopCode','workshopName','woNo','productId','dataSource','dataSourceCreateTime','pushTime'))
      }
      
    }
  }
</script>

<style lang="less" scoped>
/** Button按钮间距 */
  .ant-btn {
    margin-left: 30px;
    margin-bottom: 30px;
    float: right;
  }
</style>